/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.sequence.helper;

import java.util.ArrayList;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Event;
import org.eclipse.uml2.uml.Lifeline;
import org.eclipse.uml2.uml.TimeObservation;

import com.cea.papyrus.core.helper.GraphEdgeHelper;
import com.cea.papyrus.core.helper.IGraphEdgeHelper;
import com.cea.papyrus.diagram.sequence.ui.dialogs.ChooseEventofLifeLineDialog;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * 
 */
public class EdgeTimeObservationHelper extends GraphEdgeHelper implements IGraphEdgeHelper{

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.IGraphEdgeFactory#canExecute(com.cea.papyrus.diagraminterchange2.di2.GraphNode, com.cea.papyrus.diagraminterchange2.di2.GraphNode)
	 */	
	/**
	 * 
	 * 
	 * @param target 
	 * @param source 
	 * 
	 * @return 
	 */
	@Override
	public boolean canConnect(Element source,Element target){
		if (source==target){return false;}// generalization not on the same object
		if (source instanceof TimeObservation&& target== null) {// they are  classifiers
			return true;
		}
	
		if (source instanceof TimeObservation&& target instanceof Lifeline) {// they are  classifiers
			return true;
		}
		return false;

	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.GraphEdgeFactory#canExecute(com.cea.papyrus.diagraminterchange2.di2.GraphNode)
	 */
	/**
	 * 
	 * 
	 * @param source 
	 * 
	 * @return 
	 */
	@Override
	public boolean canCreateGraphElement(GraphElement source){
		Element eltSource=null;
		
		return true;
	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.GraphEdgeFactory#createGraphEdge(org.eclipse.uml2.uml.Element, com.cea.papyrus.diagraminterchange2.di2.Diagram)
	 */
	/**
	 * 
	 * 
	 * @param umlElement 
	 * @param diagram 
	 * 
	 * @return 
	 */
	@Override
	public ArrayList createGraphEdge(Element umlElement, Diagram diagram){

		return new ArrayList();
	}

	/**
	 * 
	 * 
	 * @param umlParent 
	 * @param name 
	 * 
	 * @return 
	 */
	public  org.eclipse.uml2.uml.Element createUMLElement(String name, org.eclipse.uml2.uml.Element umlParent){
		return null;		
	}


	/**
	 * 
	 * 
	 * @param umlParent 
	 * 
	 * @return 
	 */
	public boolean canCreateUMLElement(Element umlParent) {
		return false;
	}


	/**
	 * 
	 * 
	 * @param element 
	 * @param umlParent 
	 * 
	 * @return 
	 */
	public boolean addUMLElement(Element element, Element umlParent) {
		return false;
	}


	/**
	 * 
	 * 
	 * @param element 
	 * @param umlParent 
	 * 
	 * @return 
	 */
	public boolean removeUMLElement(Element element, Element umlParent) {
		return false;
	}
	
	/**
	 * 
	 * 
	 * @param target 
	 * @param link 
	 * @param source 
	 * 
	 * @return 
	 */
	public boolean connect(Element source, Element target, Element link) {
		ChooseEventofLifeLineDialog celd= new ChooseEventofLifeLineDialog(new Shell(),(Lifeline)target);
		celd.open();
		Event event= celd.getResult();
		((TimeObservation)source).setEvent(event);
		return true;
	}
	
	/**
	 * 
	 * 
	 * @param target 
	 * @param link 
	 * @param source 
	 * 
	 * @return 
	 */
	public boolean deconnect(Element source, Element target, Element link) {
		((TimeObservation)source).setEvent(null);
		
		return true;
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	public String getBaseString() {
		return "Link"; //$NON-NLS-1$
	}

}
